package servlet.musicBoxe;

import com.alibaba.fastjson.JSON;
import pojo.Result;
import service.MusicBoxesService;
import service.impl.MusicBoxesServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/musicBoxes/delete")
public class MusicBoxesDelete extends HttpServlet {
    MusicBoxesService musicBoxesService = new MusicBoxesServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String musicBoxesIdStr = req.getParameter("musicBoxesId");
        Result result = null;
        if (musicBoxesService.deleteMusicBox(Integer.parseInt(musicBoxesIdStr))) {
            result = Result.success();
        } else {
            result = Result.error("删除失败");
        }
        resp.setContentType("text/json;charset=utf-8");
        resp.getWriter().write(JSON.toJSONString(result));
    }
}
